package ru.jexp.rcp.supply;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.ICoolBarManager;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;

import ru.jexp.rcp.supply.actions.ActionDelete;
import ru.jexp.rcp.supply.actions.ActionMenuCreatorWizard;
import ru.jexp.rcp.supply.actions.ActionNewPattern;
import ru.jexp.rcp.supply.actions.ActionOpen;
import ru.jexp.rcp.supply.actions.ActionOpenNavigationView;
import ru.jexp.rcp.supply.actions.wizards.ActionNewWizardAccount;
import ru.jexp.rcp.supply.actions.wizards.ActionNewWizardNakl;
import ru.jexp.rcp.supply.actions.wizards.ActionNewWizardProj;
import ru.jexp.rcp.supply.actions.wizards.ActionNewWizardZs;
import ru.jexp.rcp.supply.actions.wizards.ActionNewWizardZt;
import ru.jexp.rcp.supply.beans.correlate.ActionCorrelateWizard;
import ru.jexp.rcp.supply.mui.JExpSupplyMessages;

public class ApplicationActionBarAdvisor extends ActionBarAdvisor {

	private ActionNewPattern actionNewPattern;
	private ActionDelete actionDelete;
	private ActionOpen actionOpen;
	private ActionOpenNavigationView actionOpenNavView;

	private IAction actionOpenWizardProj;
	private ActionNewWizardZs actionOpenWizardZs;
	private ActionNewWizardZt actionOpenWizardZt;
	private ActionNewWizardAccount actionOpenWizardAccount;

	private IWorkbenchAction actionExit;
	private IWorkbenchAction actionNewWizard;
	private IWorkbenchAction actionSaveEditor;
	private ActionNewWizardNakl actionOpenWizardNakl;
	private ActionCorrelateWizard actionCorrelate;

	public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
		super(configurer);
	}

	protected void makeActions(IWorkbenchWindow window) {
		actionNewPattern = new ActionNewPattern(window);
		actionSaveEditor = ActionFactory.SAVE.create(window);
		actionDelete = new ActionDelete(window);
		actionOpen = new ActionOpen(window);
		actionOpenNavView = new ActionOpenNavigationView(window);
		actionOpenWizardProj = new ActionNewWizardProj(window);
		actionOpenWizardZs = new ActionNewWizardZs(window);
		actionOpenWizardZt = new ActionNewWizardZt(window, SWT.NONE);
		actionOpenWizardAccount = new ActionNewWizardAccount(window);
		actionOpenWizardNakl = new ActionNewWizardNakl(window);
		actionCorrelate = new ActionCorrelateWizard(window);

		actionNewWizard = ActionFactory.NEW_WIZARD_DROP_DOWN.create(window);
		actionNewWizard.setMenuCreator(new ActionMenuCreatorWizard(window));
		actionExit = ActionFactory.QUIT.create(window);

		register(actionNewPattern);
		register(actionSaveEditor);
		register(actionDelete);
		register(actionOpen);
		register(actionOpenNavView);
		register(actionOpenWizardZs);
		register(actionOpenWizardZt);
		register(actionOpenWizardAccount);
		register(actionOpenWizardNakl);

		register(actionExit);
		register(actionNewWizard);

	}

	protected void fillMenuBar(IMenuManager menuBar) {
		MenuManager file = new MenuManager(JExpSupplyMessages.File_menu, "jexpfile");
		file.add(actionNewWizard);
		file.add(actionNewPattern);
		file.add(new Separator());
		file.add(actionSaveEditor);
		file.add(new Separator());
		file.add(actionExit);
		menuBar.add(file);

		MenuManager edit = new MenuManager(JExpSupplyMessages.Edit_menu, "jexpedit");
		edit.add(actionOpen);
		edit.add(actionDelete);
		menuBar.add(edit);

		MenuManager view = new MenuManager(JExpSupplyMessages.View_menu, "jexpview");
		menuBar.add(view);
		
		MenuManager project = new MenuManager(JExpSupplyMessages.Project_menu, "jexpproject");
		menuBar.add(project);
		
		MenuManager documents = new MenuManager(JExpSupplyMessages.Documents_menu, "jexpdocuments");
		menuBar.add(documents);
		
		MenuManager report = new MenuManager(JExpSupplyMessages.Report_menu, "jexpreport");
		menuBar.add(report);
		
//		MenuManager help = new MenuManager(JExpSupplyMessages.Help_menu, IWorkbenchActionConstants.M_HELP);
//		menuBar.add(help);
	}

	@Override
	protected void fillCoolBar(ICoolBarManager coolBar) {
		ToolBarManager file = new ToolBarManager();
		file.add(actionNewWizard);
		file.add(actionNewPattern);
		file.add(actionSaveEditor);
		coolBar.add(file);

		ToolBarManager edit = new ToolBarManager();
		edit.add(actionDelete);
		coolBar.add(edit);

		//ToolBarManager view = new ToolBarManager();
		//view.add(actionOpenNavView);
		//coolBar.add(view);
		
		//ToolBarManager export = new ToolBarManager();
		//export.add(actionPrint);
		//coolBar.add(export);

		ToolBarManager wizards = new ToolBarManager();
		wizards.add(actionOpenWizardProj);
		wizards.add(actionOpenWizardZs);
		wizards.add(createOpenWizardRequirment());
		wizards.add(actionOpenWizardAccount);
		wizards.add(actionOpenWizardNakl);
		coolBar.add(wizards);
		
		ToolBarManager service = new ToolBarManager();
		service.add(actionCorrelate);
		coolBar.add(service);

	}

	private IAction createOpenWizardRequirment() {
		//ActionMenuCreator creator = new ActionMenuCreator();
		ActionNewWizardZt reqiurment = new ActionNewWizardZt(
				getActionBarConfigurer().getWindowConfigurer().getWindow(),
				IAction.AS_UNSPECIFIED/*IAction.AS_DROP_DOWN_MENU*/);
		//creator.addAction(actionOpenWizardAccount);
		//reqiurment.setMenuCreator(creator);
		return reqiurment;
	}

}
